package com.example.vue.account.action;

import com.example.vue.account.service.AccountService;
import com.example.vue.account.vo.AccountLoginFormVo;
import com.example.vue.account.vo.AccountRegFormVo;
import com.example.vue.comm.domain.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

/**
 * 用户的账号管理接口
 *
 * @author zhouxl
 * @DATE 2020/11/27
 * @descriptoin
 */
@Api("用户管理")
@Controller
@RequestMapping("/api/account/")
public class AccountAction {

    @Autowired
    private AccountService accountService;

    /**
     * 账户注册接口
     *
     * @param vo 账户注册的信息
     * @return
     */
    @ApiOperation("注册用户接口")
    @RequestMapping(value = "register", method = RequestMethod.POST)
    @ResponseBody
    public ResultData register(AccountRegFormVo vo) throws NoSuchAlgorithmException {
        ResultData data = accountService.register(vo);
        return data;
    }

    /**
     * 用户登录
     *
     * @param vo
     * @return
     */
    @ApiOperation("用户登录接口")
    @RequestMapping(value = "login", method = RequestMethod.POST)
    @ResponseBody
    public ResultData login(AccountLoginFormVo vo, HttpServletResponse response) throws NoSuchAlgorithmException {
        ResultData result = accountService.login(vo, response);
        return result;
    }

    /**
     * 查询用户列表信息
     *
     * @return
     */
    @RequestMapping(value = "queryAccountList", method = RequestMethod.POST)
    @ResponseBody
    public Object queryAccountList(@RequestParam Map<String, Object> params) {
        return accountService.queryAccountList(params);
    }

    /**
     * 编辑保存用户信息
     *
     * @return
     */
    @RequestMapping(value = "saveAccount", method = RequestMethod.POST)
    @ResponseBody
    public Object saveAccount(@RequestParam Map<String, Object> params) {
        return accountService.saveAccount(params);
    }

    /**
     * 删除用户信息
     *
     * @return
     */
    @RequestMapping(value = "deleteAccount", method = RequestMethod.POST)
    @ResponseBody
    public Object deleteAccount(@RequestParam Map<String, Object> params) {
        return accountService.deleteAccount(params);
    }

    /**
     * 重置用户密码
     *
     * @return
     */
    @RequestMapping(value = "resetPassAccount", method = RequestMethod.POST)
    @ResponseBody
    public Object resetPassAccount(@RequestParam Map<String, Object> params) throws Exception {
        return accountService.resetPassAccount(params);
    }

    /**
     * 获取用户的权限信息
     *
     * @return
     */
    @RequestMapping(value = "queryAccountMenu", method = RequestMethod.POST)
    @ResponseBody
    public Object queryAccountMenu(@RequestParam Map<String, Object> params) {
        return accountService.queryAccountMenu(params);
    }

    /**
     * 保存用户权限信息
     *
     * @return
     */
    @RequestMapping(value = "saveAccountMenu", method = RequestMethod.POST)
    @ResponseBody
    public Object saveAccountMenu(@RequestParam Map<String, Object> params) {
        return accountService.saveAccountMenu(params);
    }

    /**
     * 改变用户性别
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "changeAccountGender", method = RequestMethod.POST)
    @ResponseBody
    public Object changeAccountGender(@RequestParam Map<String, Object> params) {
        return accountService.changeAccountGender(params);
    }

    /**
     * 用户状态修改
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "changeAccountStatus", method = RequestMethod.POST)
    @ResponseBody
    public Object changeAccountStatus(@RequestParam Map<String, Object> params) {
        return accountService.changeAccountStatus(params);
    }

    /**
     * 查询用户的菜单信息
     *
     * @return
     */
    @RequestMapping(value = "queryAccountLeftNavMenu", method = RequestMethod.POST)
    @ResponseBody
    public Object queryAccountLeftNavMenu(@RequestParam Map<String, Object> params) {
        return accountService.queryAccountLeftNavMenu(params);
    }

    /**
     * 退出接口
     *
     * @return
     */
    @RequestMapping(value = "loginout", method = RequestMethod.POST)
    @ResponseBody
    public Object loginout(@RequestParam Map<String, Object> params) {
        return accountService.loginout(params);
    }

}
